<?php
namespace Home\Controller;

use Think\Controller;
class MainController extends Controller {
    //商城主页
    public function member(){
        $id = session('id');
        $where['idi'] = $id;
        $wh['informatio_id'] = $id;
        $w['idi'] = $id;
        $wh['zhuangtai'] = "已付款";
        $se = M('purchase')->where($wh)->select();
        if(!empty($id)){
            if(count($se)>=10){
                $da['grade'] = "铜牌";
                M('information')->where($w)->save($da);
            }else if (count($se)>=20 ){
                $daq['grade'] = "银牌";
                M('information')->where($w)->save($daq);
            }else if (count($se)>=30 ){
                $daw['grade'] = "金牌";
                M('information')->where($w)->save($daw);
            }else if (count($se)>=40 ){
                $dae['grade'] = "白金";
                M('information')->where($w)->save($dae);
            }else if (count($se)>=50 ){
                $dar['grade'] = "钻石";
                M('information')->where($w)->save($dar);
            }
        }
        $this->name = M('information')->join('purse on information_id = information.idi')->where($where)->select();
        $this->display('Member:index');
    }

    public function infor(){
        $id = session('id');
        $whe['idi'] = $id;
        $this->name =M('information')->where($whe)->select();
        $this->display('Infor:index');
    }
    public function order(){
        $id = session('id');
        $whr['infors_id'] = $id;
        $this->name = M('Address')->where($whr)->select();
        $this->display('Order/index');
    }

    public function rtyf(){
        $idu = $_REQUEST['id'];
        $ids =session('id');//用户id
        $where['idit'] = $idu;
        $where['idi'] = $ids;
        $this->name = M('shop')->join('purchase on shopsid =shop.idit')->join('information on information.idi =informatio_id')->join('Address on information.idi =infors_id')->where($where)->select();
        $this->display('Shopping/quren');
    }

    public function orefs(){
        $id = session('id');
        $where['informatio_id'] = $id;
        $this->name =M('purchase')->join('shop on shopsid=shop.idit')->where($where)->order('f_time desc')->select();
        $this->display("Order:orefs");
    }
}